/*
 * Translated default messages for the jQuery validation plugin.
 * Locale: CN
 */
jQuery.extend(jQuery.validator.messages, {
		required: Lenovo.language.error.required,
		remote: Lenovo.language.error.remote,
		email: Lenovo.language.error.email,
		url: Lenovo.language.error.url,
		date: Lenovo.language.error.date,
		dateISO: "Please enter a valid date (ISO).",
		number: Lenovo.language.error.number,
		digits: Lenovo.language.error.digits,
		creditcard: Lenovo.language.error.creditcard,
		equalTo: Lenovo.language.error.equalTo,
		accept: Lenovo.language.error.accept,
		maxlength: $.validator.format(Lenovo.language.error.maxlength),
		minlength: $.validator.format(Lenovo.language.error.minlength),
		rangelength: $.validator.format(Lenovo.language.error.rangelength),
		range: $.validator.format(Lenovo.language.error.range),
		max: $.validator.format(Lenovo.language.error.max),
		min: $.validator.format(Lenovo.language.error.min)
});

//errorPlacement
//jQuery.extend(jQuery.validator.prototype.showLabel,function(element,error){
//	alert("aaaaaaaaaaaaaaaa");
//	alert(error);
//	//error.appendTo(element.parent("div").parent("div").next("div"));
//});


//extend jquery.validate.only 验证名字和code的唯一性

$.validator.addMethod('onlyCreate', function(value, element){
	var params = {};
	params[element.name] = value;
	params['entity'] = $('input[name=entity]').val();
	var result = Util.ajaxAsync('/search/only/create', params) == '1' ? false : true;
	return this.optional(element) || result;
}, $.validator.format(Lenovo.language.error.only));

$.validator.addMethod('onlyUpdate', function(value, element){
	var params = {};
	params[element.name] = value;

	//每个添加或者是修改页面必须有name = entity && name = id 的隐藏域
	params['entity'] = $('input[name=entity]').val();
	params['id'] = $('input[name=id]').val();
	var result = Util.ajaxAsync('/search/only/update', params) == '1' ? false : true;
	return this.optional(element) || result;
}, $.validator.format(Lenovo.language.error.only));

//validate ipAddr
$.validator.addMethod('ip', function(value, element){
	return this.optional(element) || /^([1-9]|[1-9]\d|1\d{2}|2[0-1]\d|22[0-3])(\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])){3}$/.test(value);
}, Lenovo.language.error.ip);

//validate ipAddr
$.validator.addMethod('gt_0', function(value, element){
	return this.optional(element) || /^[1-9][0-9]*$/.test(value);
}, Lenovo.language.error.number);

//validate port
$.validator.addMethod('multPort', function(value, element){
	return this.optional(element) || /^[1-9][0-9,]*[0-9]$/.test(value);
}, Lenovo.language.error.multPort);

$.validator.addMethod('selectNotEmpty',function(value, element){
	var $id = element['id'];
	if ($id == undefined || "" == $id) {
		alert("请为你要较验Select添加ID字段值，并要和Name字段值相同 ！");
		return false;
	}
	$selectValue = $("input[name=" + $id + "]").val();
	if ($selectValue == undefined || $selectValue == "") {
		return false;
	}
	return true;
},Lenovo.language.error.required);


//datagrid
$.validator.addMethod('dgNotEmpty',function(value, element){
	var $id = $(element).attr('target');
	if ($id == undefined || "" == $id) {
		alert("请为你要较验Select添加ID字段值，并要和Name字段值相同 ！");
		return false;
	}
	$selectValue = $("input[name=" + $id + "]").val();
	if ($selectValue == undefined || $selectValue == "") {
		return false;
	}
	
	return true;
	
},Lenovo.language.error.required);

//添加AMT密码较验规则
$.validator.addMethod('AMTpwd',function(value, element){
	var s = element['value'];

 	var reg1 = /[a-z]/;
 	var reg2 = /[A-Z]/;
	var reg3 = /[0-9]/;
 	var reg4 = /[!@#$%^&*{}]/;
	
	var reg5 = /^[a-zA-Z0-9!@#$%^&*]{8,15}$/;


	return (reg2.test(s) && reg1.test(s) && reg3.test(s) && reg4.test(s) && reg5.test(s) && s.length > 7 && s.length < 16);

},Lenovo.language.error.amtpwd);

//添加用户修改密码的较验
$.validator.addMethod('isOldPwd',function(value, element){
	var s = element['value'];

	var result = Util.ajaxAsync('/user/isoldpwd', {'pp': s}) == '1' ? false : true;
	return result;
},Lenovo.language.error.pwd.pwdnotthesame);

//添加用户修改密码的较验
$.validator.addMethod('newPass',function(value, element){
	var $newpass = $(".newPass");
	var _1 = $newpass.get(0).value == $newpass.get(1).value;
	if (_1) {
		return true;
	} else {
		if (element.alt == "error") {
			return false;
		}
		return true;
	} 
},Lenovo.language.error.newpassnotsame);

//字符验证 
jQuery.validator.addMethod("stringCheck", function(value, element) {
	return this.optional(element) || /^[\u0391-\uFFE5\w]+$/.test(value);
}, "只能包括中文字、英文字母、数字和下划线");
// 中文字两个字节 
jQuery.validator.addMethod("byteRangeLength", function(value, element, param) {
	var length = value.length;
	for ( var i = 0; i < value.length; i++) {
		if (value.charCodeAt(i) > 127) {
			length++;
		}
	}
	return this.optional(element) || (length >= param[0] && length <= param[1]);
}, "请确保输入的值在3-15个字节之间(一个中文字算2个字节)");
// 身份证号码验证 
jQuery.validator.addMethod("isIdCardNo", function(value, element) {
	return this.optional(element) || isIdCardNo(value);
}, "请正确输入您的身份证号码");
// 手机号码验证 
jQuery.validator.addMethod("isMobile", function(value, element) {
	var length = value.length;
	var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;
	return this.optional(element) || (length == 11 && mobile.test(value));
}, Lenovo.language.error.isMobile);
// 电话号码验证 
jQuery.validator.addMethod("isTel", function(value, element) {
	var tel = /^\d{3,4}-?\d{7,9}$/; //电话号码格式010-12345678 
	return this.optional(element) || (tel.test(value));
}, Lenovo.language.error.isTel);
jQuery.validator.addMethod("aPhone", function(value, element) {
	var tel = /^\d{3,4}-?\d{7,9}$/; //电话号码格式010-12345678 
	return this.optional(element) || (tel.test(value));
}, Lenovo.language.error.isTel);
// 联系电话(手机/电话皆可)验证 
jQuery.validator.addMethod("isPhone", function(value, element) {
	var length = value.length;
	var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;
	var tel = /^\d{3,4}-?\d{7,9}$/;
	return this.optional(element) || (tel.test(value) || mobile.test(value));
}, Lenovo.language.error.isPhone);
// 邮政编码验证 
jQuery.validator.addMethod("isZipCode", function(value, element) {
	var tel = /^[0-9]{6}$/;
	return this.optional(element) || (tel.test(value));
}, "请正确填写您的邮政编码");

//isMobile请正确填写您的手机号码
//isPhone请正确填写您的联系电话
//isTel请正确填写您的电话号码

$.validator.addMethod('logdate', function(value, element) {
	if(value == "")
		return false;
	var reg = /^([0-9]{4})(-([0-9]{2})){2}$/;
	return this.optional(element) || (reg.test(value));
},Lenovo.language.sys.config.systemservice.validate.hour);